package com.cti.commons.delayqueue.handler;

import org.springframework.web.method.support.InvocableHandlerMethod;

import com.cti.commons.delayqueue.core.mode.DelayMessage;

import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;

/**
 * @author et.wang
 * @description: 消息处理
 * @date 2022/11/21 14:58
 */
@Slf4j
@AllArgsConstructor
public class DelayQueueListenerHandler {

    private String topic;

    private final InvocableHandlerMethod invocableHandlerMethod;

    public boolean handleMessage(DelayMessage delayMessage) throws Exception {
        return (boolean) this.invocableHandlerMethod.invokeForRequest(null, null, delayMessage);
    }

    public String getTopic() {
        return topic;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        DelayQueueListenerHandler handler = (DelayQueueListenerHandler) o;
        return topic.equals(handler.topic);
    }

    @Override
    public int hashCode() {
        int result = topic.hashCode();
        result = 31 * result + invocableHandlerMethod.hashCode();
        return result;
    }

}
